package com.sxdx.service.impl;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;
import com.sxdx.dao.OrderinfoDAO;
import com.sxdx.entity.Orderinfo;
import com.sxdx.service.ExcelService;
import com.sxdx.util.ExportExcel;

@SuppressWarnings("all")
@Component("excelService")
public class ExcelServiceImpl implements ExcelService {
	private static Logger logger = LogManager.getLogger(Thread.currentThread().getStackTrace()[1].getClassName());
	@Resource(name = "orderinfoDAO")
	private OrderinfoDAO orderinfoDAO;

	public void expexcel(FileOutputStream out, String name, List<Orderinfo> orderinfolist) {
		ExportExcel.expExcel(out, name, orderinfolist);
	}

	public List<Orderinfo> findorder(String name, int week, String[] labids) {
		if (name.equals("admin")) {
			String hql = "from Orderinfo o where o.OWeek=? and o.OLabId=?";
			List<Object> param = new ArrayList<Object>();
			param.add(week);
			param.add(null);
			List<Orderinfo> l = new ArrayList<Orderinfo>();
			for (int j = 0; j < labids.length; j++) {
				param.set(1, Integer.parseInt(labids[j]));
				l.addAll(orderinfoDAO.find(hql, param));
			}
			return l;
		} else {
			String hql = "from Orderinfo o where o.OTeacherName=? and o.OWeek=? and o.OLabId=?";
			List<Object> param = new ArrayList<Object>();
			param.add(name);
			param.add(week);
			param.add(null);
			List<Orderinfo> l = new ArrayList<Orderinfo>();
			for (int j = 0; j < labids.length; j++) {
				param.set(2, Integer.parseInt(labids[j]));
				l.addAll(orderinfoDAO.find(hql, param));
			}
			return l;
		}
	}
}
